const httpCodes = require("./http-codes");
const db = uniCloud.database();
const collection = db.collection("opendb-banner");

module.exports = {
  async getBanners() {
    try {
      const res = await collection
        .where({
          status: true, // 只获取启用的banner
        })
        .orderBy("sort", "asc") // 按sort字段排序
        .get();

      return {
        code: httpCodes.SUCCESS,
        data: res.data,
        message: "获取banner成功",
      };
    } catch (error) {
      console.error("获取banner失败:", error);
      return {
        code: httpCodes.INTERNAL_SERVER_ERROR,
        data: null,
        message: "获取banner失败",
      };
    }
  },
};
